package com.weido.nettyServer.utils;

import java.util.HashMap;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtil {
    
    private static ObjectMapper mapper;

    static {
        mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
                false);
    }
    
    public static String serialize(Object obj) throws Exception {

        if (obj == null) {
            throw new IllegalArgumentException("obj should not be null");
        }
        return mapper.writeValueAsString(obj);
    }
    
    public static void main(String[] args) throws Exception {
        System.out.println(serialize(new HashMap(){{put("name","zhangsan");}}));
    }
}